using System;
using System.Collections.Generic;
using System.Drawing;

namespace Clandestine.Engines.Field
{
	public static class BoundingBox
	{
		public static Rectangle Create(List<Point> points)
		{
			int u, l, r, d;
			
			u = d = points[0].Y;
			l = r = points[0].X;

			foreach (Point p in points)
			{
				u = (p.Y < u ? (int)p.Y : u);
				l = (p.X < l ? (int)p.X : l);
				d = (p.Y > d ? ((int)p.Y) + 1 : d);
				r = (p.X > r ? ((int)p.X) + 1 : r);
			}
			
			return new Rectangle(l, u, r - l, d - u);
		}
		
	}
}
